package es.aqua.aquac.pl.controller;

import java.util.List;

import org.springframework.binding.message.MessageContext;
import org.springframework.stereotype.Controller;

import es.aqua.aquac.exception.GeneralPLException;
import es.aqua.aquac.il.domain.Lectura;
import es.aqua.aquac.il.helper.LecturaHelper;
import es.aqua.aquac.util.Constants;
import es.aqua.aquac.util.KeysProperties;
import es.aqua.aquac.util.Utiles;

/**
 * Controller asociado a la pantalla de Propietario.
 * 
 */
@Controller
public class LecturaController {

	/**
	 * Atributo
	 */
	public LecturaHelper lecturaHelper;

	/**
	 * @return the lecturaHelper
	 */
	public LecturaHelper getLecturaHelper() {
		return lecturaHelper;
	}

	/**
	 * @param lecturaHelper
	 *            the lecturaHelper to set
	 */
	public void setLecturaHelper(LecturaHelper lecturaHelper) {
		this.lecturaHelper = lecturaHelper;
	}

	public List<Lectura> cargarLecturas() throws GeneralPLException {

		return lecturaHelper.cargarLecturas();

	}

	public Lectura nuevaLectura() throws GeneralPLException {

		return new Lectura();
	}

	public Lectura insertarLectura(Lectura lectura, MessageContext context) throws GeneralPLException {

		lectura.setId(null);

		lectura = lecturaHelper.insertarLectura(lectura);

		Utiles.introducirMensaje(context, Utiles.textoResource(KeysProperties.MENSAJE_INSERCION_CORRECTA), Constants.MSJ_INFO);

		return lectura;

	}
}
